import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../constants.dart';
import '../../../routes.dart';
import '../../../src/generated/models/category.pb.dart';
import 'sidebar_container.dart';

class Categories extends StatelessWidget {
  List<CategoryItem> categoryList;

  Categories({Key? key, required this.categoryList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SidebarContainer(
      title: "分类",
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: categoryList
            .map((e) => Category(title: e.name, id: e.cateId.toInt()))
            .toList(),
      ),
    );
  }
}

class Category extends StatelessWidget {
  final String title;
  final int id;

  const Category({
    Key? key,
    required this.title,
    required this.id,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
        padding: const EdgeInsets.symmetric(vertical: kDefaultPadding / 4),
        child: TextButton(
            style: ButtonStyle(
              alignment: Alignment.centerLeft,
            ),
            onPressed: () =>
                Get.toNamed(Routes.search, parameters: {"cid": id.toString()}),
            child: Text(title,
                textAlign: TextAlign.left,
                style: TextStyle(color: kDarkBlackColor))));
  }
}
